package com.aike.controller;


import com.aike.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/Grade", produces={"text/html;charset=UTF-8;","application/json;"})
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/register")
    public String register(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("gender") Integer gender, @RequestParam("classname") String classname)
    {
        return userService.register(username, password, gender, classname);
    }

    @RequestMapping("/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password)
    {
        return userService.login(username, password);
    }

    @RequestMapping("/getUserById")
    public String getUserById(@RequestParam("userId") Integer userId)
    {
        return userService.getUserById(userId);
    }

    //根据类型获取用户
    @RequestMapping("/getUserByType")
    public String getUserByType(@RequestParam("type")Integer type)
    {
        return userService.getUserByType(type);
    }

    @RequestMapping("/updateUserById")
    public String updateUserById(@RequestParam("userId")Integer userId, @RequestParam("username")String username, @RequestParam("password")String password, @RequestParam("gender")Integer gender, @RequestParam("classname")String classname, Integer type)
    {
        return userService.updateUserById(userId, username, password, gender, classname, type);
    }

    @RequestMapping("/deleteUserById")
    public String deleteUserById(@Param("userId") Integer userId)
    {
        return userService.deleteUserById(userId);
    }

}
